//
//  YGRegisterBLL.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/3/21.
//

#import "YGRegisterBLL.h"
#import "CNHTTPManager.h"
#import "YGUserTypeModel.h"
#import "YGRecommandModel.h"
#import "YGRegisterConfigureModel.h"
#import "YGUserTypeModel.h"
#import "UserInfoManager.h"
@implementation YGRegisterBLL

+ (void)requestRigisterNumberTypeWithSuccess:(void(^)(NSArray <YGUserTypeModel *>*model))successBlock fail:(void(^)(NSError *error))failBlock{
    [[CNHTTPManager shared] GET:YG_REGISTER_USER_TYPE parameters:nil success:^(id responeObj) {
        NSArray *data = [responeObj objectForKey:@"data"];
        NSArray *models = [YGUserTypeModel arrayOfModelsFromDictionaries:data error:nil];
        if (successBlock) {
            successBlock(models);
        }
    } failure:^(NSError *error, NSString *errorDes) {
        
    }];
}

+ (void)requestRigisterSickTypeWithSuccess:(void(^)(NSArray <YGSickTypeModel *>*model))successBlock fail:(void(^)(NSError *error))failBlock{
    [[CNHTTPManager shared] GET:YG_REGISTER_SICK_TYPE parameters:nil success:^(id responeObj) {
        NSArray *data = [responeObj objectForKey:@"data"];
        NSArray *models = [YGUserTypeModel arrayOfModelsFromDictionaries:data error:nil];
        if (successBlock) {
            successBlock(models);
        }
    } failure:^(NSError *error, NSString *errorDes) {
        
    }];
}

+ (void)requstAuthCodeWithType:(YGAuthCodeType)type phone:(NSString *)phone success:(void(^)(void))successBlock{
    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    [dic setObject:phone forKey:@"phone"];
    [dic setObject:[NSNumber numberWithInteger:type] forKey:@"type"];

    [[CNHTTPManager shared] GET:YG_REGISTER_CODE parameters:dic success:^(id responeObj) {
        if (successBlock) {
            successBlock();
        }
    } failure:^(NSError *error, NSString *errorDes) {
        
    }];
 
}


+ (void)requestServersuccess:(void(^)(NSString *content))successBlock{
    [[CNHTTPManager shared] GET:YG_SERVER_URL parameters:nil success:^(id responeObj) {
        NSDictionary *data = [responeObj objectForKey:@"data"];
        NSString *content = [data objectForKey:@"content"];
        if (successBlock) {
            successBlock(content);
        }
    } failure:^(NSError *error, NSString *errorDes) {
        
    }];
}

+ (void)requestSLAsuccess:(void(^)(NSString *content))successBlock{
    [[CNHTTPManager shared] GET:YG_SLA_URL parameters:nil success:^(id responeObj) {
        NSDictionary *data = [responeObj objectForKey:@"data"];
        NSString *content = [data objectForKey:@"content"];
        if (successBlock) {
            successBlock(content);
        }
    } failure:^(NSError *error, NSString *errorDes) {
        
    }];
}

+ (void)requestRecommandCode:(NSString *)code success:(void(^)(YGRecommandModel *model))successBlock fail:(void(^)(NSError *error))failBlock{
    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    [dic setObject:code forKey:@"doctorCode"];
    [[CNHTTPManager shared] GET:YG_RECOMMAND_DR_URL parameters:dic success:^(id responeObj) {
        NSDictionary *data = [responeObj objectForKey:@"data"];
        YGRecommandModel *content = [[YGRecommandModel alloc] initWithDictionary:data error:nil];
        if (successBlock) {
            successBlock(content);
        }
    } failure:^(NSError *error, NSString *errorDes) {
        if (failBlock) {
            failBlock(error);
        }
    }];
}

+ (void)rquestRegisterModel:(YGRegisterConfigureModel *)model success:(void(^)())successBlock fail:(void(^)(NSError *error))failBlock{
    NSMutableDictionary *dic =[NSMutableDictionary dictionary];
    [dic setObject:model.phone forKey:@"phone"];
    [dic setObject:model.pwd forKey:@"password"];
    [dic setObject:model.code forKey:@"code"];
    [dic setObject:model.name forKey:@"memberName"];
    [dic setObject:model.age forKey:@"age"];
    [dic setObject:model.recommandModel.hospitalsId forKey:@"hospitalsId"];
    [dic setObject:model.recommandModel.departmentId forKey:@"departmentId"];
    [dic setObject:model.bedid forKey:@"bed"];
    [dic setObject:model.recommandModel.id forKey:@"doctorId"];
    [dic setObject:model.recommandModel.code forKey:@"doctorCode"];
    NSInteger sex = 1;
    if ([model.sex isEqualToString: @"保密"]) {
        sex = 0;
    }else if ([model.sex isEqualToString:@"女"]){
        sex = 2;
    }
    [dic setObject:@(sex) forKey:@"sex"];
    NSInteger isLose = [model.lose_weight isEqual:@"是"]?1:2;
    [dic setObject:@(isLose) forKey:@"isLoseWeight"];
    [dic setObject:model.user_type.value forKey:@"status"];
    [dic setObject:model.sickType.value forKey:@"diseaseType"];
    [dic setObject:model.hospitalTime forKey:@"hospitalTime"];
    
    [[CNHTTPManager shared] POST:YG_REGISTER_URL parameters:dic success:^(id responeObj) {
        NSDictionary *data = [responeObj objectForKey:@"data"];
        YGUserInfoModel *userInfo = [[YGUserInfoModel alloc] initWithDictionary:data error:nil];
        [[UserInfoManager shareInstance] configureUserInfo:userInfo];
        if (successBlock) {
            successBlock();
        } 
    } failure:^(NSError *error, NSString *errorDes) {
        if (failBlock) {
            failBlock(error);
        }
        
    }];
}

@end
